package com.itboy.mall.pms.categorybrand.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.pms.categorybrand.vo.MallCategoryBrandVo;
import com.itboy.mall.pms.categorybrand.bo.MallCategoryBrandQueryBo;
import com.itboy.mall.pms.categorybrand.bo.MallCategoryBrandAddBo;
import com.itboy.mall.pms.categorybrand.service.IMallCategoryBrandService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 品牌分类关联Controller
 *
 * @author itboy
 * @date 2021-07-14
 */
@Api(value = "品牌分类关联控制器", tags = {"品牌分类关联管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/categoryBrand")
public class MallCategoryBrandController extends BaseController {

    private final IMallCategoryBrandService iMallCategoryBrandService;

    /**
     * 查询品牌分类关联列表
     */
    @ApiOperation("查询品牌分类关联列表")
    @PreAuthorize("@ss.hasPermi('mall:categoryBrand:list')")
    @GetMapping("/list")
    public TableDataInfo<MallCategoryBrandVo> list(@Validated MallCategoryBrandQueryBo bo) {
        return iMallCategoryBrandService.queryPageList(bo);
    }

	/**
	 * 按分类id查询品牌
	 */
	@ApiOperation("按分类id查询品牌")
	@GetMapping("/queryListByCatelogId/{catalogId}")
	public AjaxResult<List<MallCategoryBrandVo>> queryByCatelogIdList(@NotNull(message = "分类id不能为空") @PathVariable String catalogId) {
		List<MallCategoryBrandVo> data=iMallCategoryBrandService.queryListByCatelogId(catalogId);
		return AjaxResult.success(data);
	}

    /**
     * 导出品牌分类关联列表
     */
    @ApiOperation("导出品牌分类关联列表")
    @Log(title = "品牌分类关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallCategoryBrandVo> export(@Validated MallCategoryBrandQueryBo bo) {
        List<MallCategoryBrandVo> list = iMallCategoryBrandService.queryList(bo);
        ExcelUtil<MallCategoryBrandVo> util = new ExcelUtil<MallCategoryBrandVo>(MallCategoryBrandVo.class);
        return util.exportExcel(list, "品牌分类关联");
    }



    /**
     * 新增品牌分类关联
     */
    @ApiOperation("新增品牌分类关联")
    @Log(title = "品牌分类关联", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallCategoryBrandAddBo bo) {
        return toAjax(iMallCategoryBrandService.insertByAddBo(bo) ? 1 : 0);
    }


    /**
     * 删除品牌分类关联
     */
    @ApiOperation("删除品牌分类关联")
    @Log(title = "品牌分类关联" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] ids) {
        return toAjax(iMallCategoryBrandService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
